//
//  ZipClass.m
//  Manager
//
//  Created by 彭凯敏 on 15/9/2.
//  Copyright (c) 2015年 52xiaoluo. All rights reserved.
//

#import "ZipClass.h"
#import <ZipArchive.h>
@implementation ZipClass



//压缩文件
- (void)zipFile:(id)sender {
    
    NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
    
    NSString *imgPath = [cachesPath stringByAppendingPathComponent:@"baidu.png"];
    NSString *zipFilePath = [docsPath stringByAppendingPathComponent:@"newZipFile.zip"];
    
    //实例化一个压缩文档，并创建文件
    ZipArchive *za = [[ZipArchive alloc]init];
    [za CreateZipFile2:zipFilePath];
    //在压缩文档中添加文件
    [za addFileToZip:imgPath newname:@"baidu_zipped.png"];
    //关闭zip文件操作
    BOOL success = [za CloseZipFile2];
    if (success) {
        SuccessShow(@"压缩成功");
    }else{
        SuccessShow(@"压缩失败");
    }
  
}
//删除压缩文件
- (void)deleteZipFile:(id)sender {
    NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    NSString *zipPath = [docsPath stringByAppendingPathComponent:@"newZipFile.zip"];
    
    //创建文件管理器
    NSFileManager *fm = [NSFileManager defaultManager];
    //判断指定路径文件是否存在
    BOOL exist = [fm fileExistsAtPath:zipPath];
    if (exist) {
        NSError *error = nil;
        [fm removeItemAtPath:zipPath error:&error];
        if (!error) {
            SuccessShow(@"删除成功");
        }else{
            SuccessShow(@"删除失败");
        }
    }else{
        SuccessShow(@"文件不存在");
    }
}


@end
